package be.idamf.flash.bytecode
{
	import be.idamf.flash.amf.TraitsInfo;
	
	import org.as3commons.bytecode.emit.IAbcBuilder;
	import org.as3commons.bytecode.emit.IClassBuilder;
	import org.as3commons.bytecode.emit.IPackageBuilder;
	
	public class ClassGenerator
	{
		public var abcBuilder:IAbcBuilder;
		
		public function ClassGenerator(abcBuilder:IAbcBuilder = null)
		{
			this.abcBuilder = abcBuilder;
		}
		
		public function generate(traitsTable:Array):void
		{
			var info:TraitsInfo;
			var packageBuilder:IPackageBuilder;
			var classBuilder:IClassBuilder;
			var property:String;
			
			for each (info in traitsTable)
			{
				packageBuilder = abcBuilder.definePackage(info.type.split("::")[0]);
				classBuilder = packageBuilder.defineClass(info.type.split("::")[1]);
				
				for each (property in info.properties)
					classBuilder.defineProperty(property);
			}
		}
	}
}